﻿/*-------------------------------------
//
//Copyright (C) 2007 开发二组 版权所有。
//
//文件名：Category.ascx.cs
//
//
//文件功能描述：显示前台页面左边的分类导航.
//
//
//创建标识：2007.11.16 王勇
//创建描述：对商品分类的部分描述..
//
//------------------------------------*/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class Common_Controls_Category : System.Web.UI.UserControl
{

    //服务的操作类
    localhost.ProductService myOperate = new localhost.ProductService();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //第一次加载进行数据绑定
            BindTable();
        }
    }


    /// <summary>
    /// 定义数据绑定大类别的方法
    /// </summary>
    protected void BindTable()
    {
       //异步调用WebService
        myOperate.GetUpperCategoryListCompleted += new localhost.GetUpperCategoryListCompletedEventHandler(myOperate_GetUpperCategoryListCompleted);

        myOperate.GetUpperCategoryListAsync();
        
    }

    
    /// <summary>
    /// 回调函数
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void myOperate_GetUpperCategoryListCompleted(object sender, localhost.GetUpperCategoryListCompletedEventArgs e)
    {
        //定义装载大类别中小类别的数据集
        DataSet dsUpperCategory = new DataSet();

        //获取结果
        dsUpperCategory = e.Result;

        //进行数据源的绑定
        dlUpperCategory.DataSource = dsUpperCategory;
        dlUpperCategory.DataBind();

    }



    /// <summary>
    /// 定义DataList中项的数据绑定事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dlUpperCategory_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        //获取该大类别的ID
        string strUpperCategoryID = ((Label)e.Item.FindControl("lblUpperCategoryID")).Text;

        //声明一个DataSet来接收数据
        DataSet dsLowerCategory = new DataSet();

        //调用WebService服务获取数据
        dsLowerCategory = myOperate.GetLowCategoryListByUpperCategoryID(strUpperCategoryID);

        //获取该打类下的DataList控件进行绑定
        ((DataList)e.Item.FindControl("dlLowerCategory")).DataSource = dsLowerCategory;
        ((DataList)e.Item.FindControl("dlLowerCategory")).DataBind();
    }
}
